package train.Test;

public class Search {
    public static void main(String[] args) {
        int[] a={12,14,25,36,47,68,79};
//        System.out.println(halfSearch(a, 12));
//        System.out.println("hello word");
        System.out.println(recurLook(a,25,0,a.length-1));

    }
    //二分查找
    public static int halfSearch(int[] arr,int k){
        int min,max,mid;
        min=0;
        max=arr.length-1;
        mid=(min+max)/2;
        while(arr[mid]!=k){
            if(k>=arr[mid])
            {
                min=mid+1;
            } else{
                if(k<arr[mid])
                    max=mid-1;
            }
            mid=(min+mid)/2;
        }
        if(max<mid) return -1;
        return mid;
    }
    //递归查找
    public static int recurLook(int[] arr,int k,int begin,int end){

        int mid=begin+(end-begin);
        if(k<arr[mid]){
            return recurLook(arr,k,begin,mid-1);
        } else if(k>arr[mid]){
            return recurLook(arr,k,mid+1,end);
        }
        else return mid;

    }

}
